package org.dwpd.controller.file;

import lombok.extern.slf4j.Slf4j;
import org.dwpd.domain.common.Result;
import org.dwpd.service.file.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/file")
public class FileUploadController {

    @Autowired
    private FileService fileService;

    /**
     * 上传文件(用户头像 || 评论图片)
     * @param file 上传的图片文件
     * @return 处理后的图片链接
     */
    @PostMapping("upload")
    public Result upload(@RequestParam("file") MultipartFile file) {
        String url = fileService.upload(file);
        log.info("上传文件路径：{}",url);
        return Result.success(url);
    }
}

